layui.use('form', function () {
    var form = layui.form;

});
var currentPage = 1;//当前页码
var pageSize = 5;//每页显示的数据量
var totalCount = 0;//总条数
var totalPage = 1;//总页码
function showData() {
    let dataA = $(".select-tj").val();
    //console.log(dataA)
    let json = {
        dataA: dataA,
        currentPage: currentPage,
        pageSize: pageSize
    }

    $(".table-tj").html("<tr><td>年份</td><td>全部（人数）</td><td>博士（人数）</td><td>硕士（人数）</td><td>本科（人数）</td><td>专科（人数）</td></tr>")
    var nian1 = [];
    let boshi = [];
    let shuoshi = [];
    let benke = [];
    let zhuanke = [];
    $.ajaxSettings.async = false;
    $.get("/data/show", json, function (date) {
        console.log(date)
        //总条数
        totalCount = date.data.total;
        //总页数
        totalPage = date.data.pages;

        $(date.data.list).each(function (i, v) {
            boshi[i] = v.doctor
            shuoshi[i] = v.master
            benke[i] = v.regular
            zhuanke[i] = v.junior
            nian1[i] = v.nian
            let temp = "<tr>" +
                "<td><a href='/data/details/" + v.nian + "'>" + v.nian + "</a></td>" +
                "<td>" + v.total + "</a></td>" +
                "<td>" + v.doctor + "</td>" +
                "<td>" + v.master + "</td>" +
                "<td>" + v.regular + "</td>" +
                "<td>" + v.junior + "</td>" +
                "</tr>"
            $(".table-tj").append(temp)
        })

        $(".select-tj").empty()
        $(".select-tj").html("<option value=''>请选择</option>")
        $(date.time).each(function (i, v) {
            //nian1[i] = v.nian
            let temp = "<option value='" + v.nian + "'>" + v.nian + "</option>"

            $(".select-tj").append(temp)

        })
        layui.form.render("select");
        //console.log(nian1)
        //console.log(boshi)
        var myChart = echarts.init(document.getElementById('main'));

        let option = {
            title: {
                x:'center',
                y:'3%',
                text: '资源学历综合表报',
            },
            tooltip: {
                trigger: 'axis'
            },
            legend: {
                x:'4%',
                y:'3%',
                // data: ['博士', '硕士', '本科', '专科']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            toolbox: {
                feature: {
                    saveAsImage: {}
                }
            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                data: nian1
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    name: '博士',
                    type: 'line',
                    stack: 'Total',
                    data: boshi
                },
                {
                    name: '硕士',
                    type: 'line',
                    stack: 'Total',
                    data: shuoshi
                },
                {
                    name: '本科',
                    type: 'line',
                    stack: 'Total',
                    data: benke
                },
                {
                    name: '专科',
                    type: 'line',
                    stack: 'Total',
                    data: zhuanke
                }

            ]
        };
        myChart.setOption(option)

    }, "json")
    showPage1()
    $.ajaxSettings.async = true;


}

//查询
function chaxun() {
    showData()
    showPage1()
}

//展示页码
function showPage1() {

    if (totalPage == 0) {
        totalPage = 1;
    }
    if (currentPage == 0) {
        currentPage = 1;
    }
    $(".showPage11").text("第" + currentPage + "页 / 共" + totalPage + "页");
}

//下一页
function next1() {
    currentPage++;
    if (currentPage > totalPage) {
        currentPage = totalPage;
        return;
    }
    showData()
}


//上一页
function prev1() {
    currentPage--;
    if (currentPage < 1) {
        currentPage = 1;
        return;
    }
    showData()
}

//首页
function start1() {
    currentPage = 1;
    showData()
}

//尾页
function end1() {
    currentPage = totalPage;
    showData()
}

